var MdView = {
    template: '#md',
    methods: {
        onRefresh(done) {
            this.noMore = false
            if (this.mDbHelper == null) {
                this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
            this.mDbHelper.equalTo('UserId', $.Encryption.user.bean.name)
            
            }
            this.mDbHelper.current = 1;
            this.mDbHelper.page = 20;
            that = this;
            loadMd(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
                done()
            })

        },

        onInfinite(done) {
            if (this.noMore) {
                done()
                return
            }
            if (this.mDbHelper == null) {
                this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
                this.mDbHelper.equalTo('UserId', $.Encryption.user.bean.name)
                
                this.mDbHelper.page = 20;
                this.mDbHelper.current = 1;
            }
            this.mDbHelper.current += 1;

            that = this;
            loadMd(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items.concat(arg)
                    that.noMore = true
                } else {
                    that.items.concat(arg)
                }
                done()
            })
        },
        onSearch(data) {

        },
        onItemClick(index) {
            // console.log(index)
            mdViewerData = this.items[index]
            $router.push('/main/mdViewer')
        }
    },
    data() {
        return {
            keywords: '',
            items: [],

            noMore: false,
            mDbHelper: null,
        }
    },
    beforeDestroy() {
        mapCatch.set('#md', {
            keywords: this.keywords,
            items: this.items,
            noMore: this.noMore,
            mDbHelper: this.mDbHelper,
        })
    },
    mounted() {
        let cacth = mapCatch.get('#md')
        if (cacth && cacth.items.length > 0) {
            this.keywords = cacth.keywords;
            this.items = cacth.items;
            this.noMore = cacth.noMore;
            this.mDbHelper = cacth.mDbHelper;
            return
        }
        if (this.items.length > 0) {
            return
        }
        if (this.mDbHelper == null) {
            this.mDbHelper = $.MdManager.newPageHelper($.Encryption.CloudTable.MdList);
            this.mDbHelper.equalTo('UserId', $.Encryption.user.bean.name)
            
            this.mDbHelper.current = 1;
            this.mDbHelper.page = 20;
            that = this;
            loadMd(this.mDbHelper, function(arg) {
                if (arg == null) {
                    $toast.show("加载失败");
                } else if (arg.length < 20) {
                    that.items = arg
                    that.noMore = true
                } else {
                    that.items = arg
                }
            })
        }
    },
}